﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Tasks;

namespace MyWp7Brand
{
    public class ExternalHyperLink : HyperlinkButton
    {

        private Uri navigateUri;
        public new Uri NavigateUri
        {
            get { return base.NavigateUri;}
            set
            {
                if (value.IsAbsoluteUri)
                {
                    base.NavigateUri = null;
                    this.navigateUri = value;
                    this.Click += new RoutedEventHandler(ExternalHyperLink_Click);
                }
                else
                {
                    if (this.navigateUri != null)
                    {
                        this.navigateUri = null;
                        base.NavigateUri = value;
                        this.Click -= ExternalHyperLink_Click;
                    }
                    else
                    {
                        base.NavigateUri = value;
                    }
                }

            }
            
        }

        void ExternalHyperLink_Click(object sender, RoutedEventArgs e)
        {
            WebBrowserTask wbt = new WebBrowserTask();
            wbt.URL = this.navigateUri.AbsoluteUri;
            wbt.Show();
        }
    }
}
